home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
newsgroups
/
misc.20010306-20010921
/
000022_news@columbia.edu _Tue Mar 13 17:21:23 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2020-01-01
|
3KB
Return-Path: <news@columbia.edu>
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by monire.cc.columbia.edu (8.9.3/8.9.3) with ESMTP id RAA14242
for <kermit.misc@cpunix.cc.columbia.edu>; Tue, 13 Mar 2001 17:21:23 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id QAA25223
for kermit.misc@watsun.cc.columbia.edu; Tue, 13 Mar 2001 16:52:59 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: fdc@columbia.edu (Frank da Cruz)
Subject: More fun with dates
Date: 13 Mar 2001 21:52:59 GMT
Organization: Columbia University
Message-ID: <98m4rr$ok4$1@newsmaster.cc.columbia.edu>
To: kermit.misc@columbia.edu
This month's Scientific American (March 2001, p.80) includes an article
"Easter as a Quasicrystal" by Ian Stewart, in which the calculation of
the date of Easter is explained (and then graphed and compared to a
crystalline lattice). A ten-step algorithm is given for calculating the
Gregorian date of Easter in any given year that is "easy to program on a
computer"). Here's an illustration of how to do it in C-Kermit 7.1,
using its new LISP-like S-expression feature:
#!/usr/local/bin/kermit +
dcl \&m[] = Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
if ( not def \%1 || not numeric \%1 ) exit 1 Usage: \%0 year
if ( < \%1 1900 || > \%1 2199 ) exit 1 "\0: 1900 <= Year < 2100"
(setq x \%1)
(setq a (mod x 19) b (truncate (/ x 100)) c (mod x 100))
(setq d (truncate (/ b 4)) e (mod b 4))
(setq g (truncate (/ (+ (* 8 b) 13) 25)))
(setq h (mod (+ (* a 19) b (- d) (- g) 15) 30))
(setq m (truncate (/ (+ a (* h 11)) 319)))
(setq j (truncate (/ c 4)) k (truncate (mod c 4)))
(setq l (truncate (mod (+ (* 2 e) (* 2 j) m (- k) (- h) 32) 7)))
(setq n (truncate (/ (+ h (- m) l 90) 25)))
(setq p (truncate (mod (+ h (- m) l n 19) 32)))
echo \fday(\m(x)\flpad(\m(n),2,0)\flpad(\m(p),2,0)) \m(p) \&m[n] \m(x)
exit
See the article for an explanation of the algorithm and see:
http://www.columbia.edu/kermit/ckermit3.html#x9
for an explanation of S-Expressions. Note that the algorithm requires
all arithmetic to be integer, not floating-point, hence the many TRUNCATE
expressions (since S-Expressions never discard fractional parts).
In UNIX, clip the program, left-justify at least the first line and change
it to point to your C-Kermit 7.1 binary, save it as "easter", then "chmod +x
easter", and then you can type:
easter 2001
(or any other year between 1900 and 2099) to find out the date for Easter
in that year (years outside that range require adjustment of the algorithm).
On other platforms, type "take easter 2001" (or other year) at the Kermit
prompt.
Exercises:
. Write a similar program for Rosh Hashanah, Passover, Ramadan, Tet,
Chinese New Year, or any other holiday based on the Lunar cycle.
. Adapt to span a wider range of years.
. Adapt to support other calendars.
- Frank